var t = require("../../@babel/runtime/helpers/interopRequireDefault")(require("../../utils/util")), a = getApp(), e = new Date();

Page({
    data: {
        member: {
            nickname: "",
            member_id: "",
            level_name: "",
            validity_value: "",
            src: "https://img2.baidu.com/it/u=1814268193,3619863984&fm=253&fmt=auto&app=138&f=JPEG?w=632&h=500",
            cumulative_share_amoun: "",
            last_period: "",
            frequency: ""
        },
        active: "",
        calendarShow: !1,
        date: "",
        maxDate: Date.parse(e),
        minDate: new Date("2000,01,01").getTime(),
        currentDate: new Date().getTime(),
        rotateIcon: !1,
        detailed: !1,
        list: [],
        detailedData: {},
        explain: !1,
        explain_html: "",
        pickStatusShow: !1,
        statusText: "全部",
        order_by_status: "",
        formatter: function(t, a) {
            return "year" === t ? "".concat(a, "年") : "month" === t ? "".concat(a, "月") : "day" === t ? "".concat(a, "日") : a;
        },
        page: 1,
        current_page: 1,
        last_page: 1,
        isLoadMore: !0
    },
    onLoad: function(t) {},
    gotoMemberGrade: function() {
        wx.navigateTo({
            url: "/packageB/member/MemberGradeList/MemberGradeList"
        });
    },
    getDesc: function() {
        var t = this, e = a.getNetAddresss("plugin.share-partner.frontend.dividend.get-description");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    explain_html: e.data.description
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.share-partner.frontend.dividend.get-statistics");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    "member.src": e.data.avatar,
                    "member.nickname": e.data.nickname,
                    "member.member_id": e.data.member_id,
                    "member.level_name": e.data.level_name,
                    "member.validity_value": e.data.expire_date,
                    "member.cumulative_share_amoun": e.data.total_money,
                    "member.last_period": e.data.money,
                    "member.frequency": e.data.total_count,
                    "member.bonus_show": e.data.bonus_show,
                    "member.bonus_num": e.data.bonus_num,
                    "member.detail_show": e.data.detail_show
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toLink: function() {
        wx.navigateTo({
            url: "/packageF/sharedPartner_bonus/sharedPartner_bonus"
        });
    },
    explainIsShow: function() {
        this.setData({
            explain: !this.data.explain
        });
    },
    sorting: function() {
        "" === this.data.active && (this.data.active = !1), this.setData({
            active: !this.data.active,
            page: 1
        }), this.getList();
    },
    onClose: function() {
        this.setData({
            calendarShow: !1
        });
    },
    delDate: function() {
        this.setData({
            date: "",
            page: 1
        }), this.getList();
    },
    tapCalendar: function() {
        this.setData({
            calendarShow: !0
        });
    },
    onConfirm: function(a) {
        this.setData({
            calendarShow: !1,
            date: t.default.formatTimeTwo(a.detail / 1e3, "Y-M-D"),
            page: 1
        }), this.getList();
    },
    tapRotateIcon: function() {
        this.setData({
            rotateIcon: !this.data.rotateIcon,
            pickStatusShow: !this.data.pickStatusShow
        });
    },
    tapPickStatus: function(t) {
        var a = t.currentTarget.dataset, e = a.status, i = a.text;
        this.setData({
            statusText: i,
            rotateIcon: !1,
            pickStatusShow: !1,
            order_by_status: e,
            page: 1
        }), this.getList();
    },
    detailedIsShowClose: function() {
        this.setData({
            detailed: !1
        });
    },
    detailedIsShow: function(t) {
        var a = t.currentTarget.dataset.item.id;
        this.getDetail(a);
    },
    receive: function(t) {
        var a = t.currentTarget.dataset.item.id;
        this.getDraw(a);
    },
    getDraw: function(t) {
        var e = this, i = this, s = {
            dividend_id: t
        }, n = a.getNetAddresss("plugin.share-partner.frontend.dividend.draw");
        a._getNetWork({
            url: n,
            data: s,
            success: function(a) {
                var s = a.data;
                if (1 == s.result) if (1 == s.data.status) wx.showModal({
                    title: "领取成功",
                    content: "恭喜您已经成功领取奖励",
                    success: function(t) {
                        i.setData({
                            page: 1,
                            current_page: 1,
                            last_page: 1
                        }), i.getList();
                    }
                }); else {
                    if (2 != s.data.status) return;
                    e.getAdv(t);
                } else wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getAdv: function(t) {
        var e = a.getNetAddresss("plugin.flyers-advertise.frontend.mini.index");
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var i = e.data.mini_form_id || "", s = e.data.adv_list[0].adv_id;
                    wx.redirectTo({
                        url: "/packageI/AdBright/AdBrightPage/AdBrightPage?adv_id=" + s + "&wxad=" + i + "&Partner=Partner&pid=" + t,
                        fail: function(t) {
                            console.log(t), wx.showToast({
                                title: "请使用多功能版本小程序",
                                icon: "none",
                                duration: 2e3
                            });
                        }
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getDetail: function(t) {
        var e = this, i = {
            id: t,
            page: this.data.page
        }, s = a.getNetAddresss("plugin.share-partner.frontend.dividend.get-detail");
        a._getNetWork({
            url: s,
            data: i,
            success: function(t) {
                var a = t.data;
                1 == a.result ? e.setData({
                    detailedData: a.data,
                    detailed: !0
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getData(), this.getDesc(), this.getList();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    getMore: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.current_page >= this.data.last_page)) {
            var e = {
                status: this.data.order_by_status,
                time: this.data.date,
                page: this.data.page + 1
            };
            "" !== this.data.active && (e.order_by = this.data.active ? "asc" : "desc");
            var i = a.getNetAddresss("plugin.share-partner.frontend.dividend.get-list");
            a._getNetWork({
                url: i,
                data: e,
                success: function(a) {
                    t.data.isLoadMore = !0;
                    var e = a.data;
                    1 == e.result ? t.setData({
                        page: t.data.page + 1,
                        list: t.data.list.concat(e.data.data),
                        current_page: e.data.current_page,
                        last_page: e.data.last_page
                    }) : wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    this.data.isLoadMore = !0, console.log(t);
                }
            });
        }
    },
    getList: function() {
        var t = this, e = {
            status: this.data.order_by_status,
            time: this.data.date,
            page: this.data.page
        };
        "" !== this.data.active && (e.order_by = this.data.active ? "desc" : "asc");
        var i = a.getNetAddresss("plugin.share-partner.frontend.dividend.get-list");
        a._getNetWork({
            url: i,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    list: e.data.data,
                    current_page: e.data.current_page,
                    last_page: e.data.last_page
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReachBottom: function() {
        this.data.isLoadMore && this.getMore();
    },
    onShareAppMessage: function() {}
});